//
//  OYToolBarView.swift
//  weiboCopycat
//
//  Created by Orange Yu on 2016/12/5.
//  Copyright © 2016年 Orange Yu. All rights reserved.
//

import UIKit

class OYHomeToolBarView: UIView {

     // MARK: -viewModel的观察者属性 - 为控件动态设置数据
    var statusVM: OYStatusViewModel? {
        didSet {
            
            repostButton.setTitle(statusVM?.repostTitle, for: .normal)
            commentButton.setTitle(statusVM?.commentTitle, for: .normal)
            likeButton.setTitle(statusVM?.likeTitle, for: .normal)
        }
    }
    
    
     // MARK: -控件的懒加载
    /// 转发button控件
    lazy var repostButton: UIButton = {
        let button = UIButton(title: "转发", imageName: "timeline_icon_retweet", backgroundImageName: "timeline_card_bottom_background")
        return button
    }()
    /// 评论button控件
    lazy var commentButton: UIButton = {
        let button = UIButton(title: "评论", imageName: "timeline_icon_comment", backgroundImageName: "timeline_card_bottom_background")
        return button
    }()
    /// 点赞button控件
    lazy var likeButton: UIButton = {
        let button = UIButton(title: "赞", imageName: "timeline_icon_unlike", backgroundImageName: "timeline_card_bottom_background")
        return button
    }()
    /// button中间的分隔线
    lazy var leftButtonSeperatorLine: UIImageView = {
        let imageView = UIImageView(image: UIImage(named:"timeline_card_bottom_line"))
        return imageView
    }()
    lazy var rightButtonSeperatorLine: UIImageView = {
        let imageView = UIImageView(image: UIImage(named:"timeline_card_bottom_line"))
        return imageView
    }()
    /// view中间的分隔线
    lazy var viewSeperatorLine: UIImageView = {
        let imageView = UIImageView(image: UIImage(named:"timeline_card_bottom_line"))
        return imageView
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    func setupUI()  {
        addSubview(repostButton)
        addSubview(commentButton)
        addSubview(likeButton)
        addSubview(leftButtonSeperatorLine)
        addSubview(rightButtonSeperatorLine)
        addSubview(viewSeperatorLine)
        
        repostButton.snp_makeConstraints { (make) in
            make.left.equalTo(self)
            make.top.equalTo(viewSeperatorLine.snp_bottom)
            make.width.equalTo((ScreenWidth - 2 )/3)
        }
        
        leftButtonSeperatorLine.snp_makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.width.equalTo(1)
            make.left.equalTo(repostButton.snp_right)
            make.height.equalTo(30)
        }
        
        commentButton.snp_makeConstraints { (make) in
            make.top.equalTo(repostButton)
            make.left.equalTo(leftButtonSeperatorLine.snp_right)
            make.width.equalTo((ScreenWidth - 2)/3)
        }
        
        rightButtonSeperatorLine.snp_makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.width.equalTo(1)
            make.left.equalTo(commentButton.snp_right)
            make.height.equalTo(30)
        }
        
        likeButton.snp_makeConstraints { (make) in
            make.top.equalTo(commentButton)
            make.left.equalTo(rightButtonSeperatorLine.snp_right)
            make.width.equalTo((ScreenWidth - 2)/3)
        }
        
        viewSeperatorLine.snp_makeConstraints { (make) in
            make.left.right.top.equalTo(self)
            make.height.equalTo(1)
        }
    }

    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
 
}
